package com.yueyang.sojourn.server.controller;

import com.yueyang.sojourn.server.controller.model.JsonResult;
import com.yueyang.uc.model.LoginTokenV1;
import com.yueyang.uc.model.UcUserV1;
import com.yueyang.uc.spi.LoginUserSpi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Stephen.Shi
 * @version v1
 * @summary
 * @Copyright (c) 2019, yueyang Group All Rights Reserved.
 * @since 2020/2/2
 */
@RestController
@RequestMapping("/sojourn/user/")
@Slf4j
public class UserController extends BaseController{
    @Autowired
    private LoginUserSpi loginUserSpi;

    @PostMapping("/login")
    public JsonResult<LoginTokenV1> login(@RequestParam("username") String username, @RequestParam("password") String password) {
        return ok().of(loginUserSpi.login(username, password));
    }

    @PostMapping("/logout")
    public JsonResult logout(@RequestHeader("X-Token") String token) {
        loginUserSpi.logout(token);
        return ok("登出成功");
    }

    @GetMapping("/info")
    public JsonResult<UcUserV1> userInfo(@RequestHeader("X-Token") String token) {
        return ok().of(loginUserSpi.userInfo(token));
    }

}
